<?php
class Frontendmodel extends CI_Model {

	var $title   = '';
	var $content = '';
	var $date    = '';
	
	function __construct()
	{
		parent::__construct();
	}
	public function getCss($css, $source = "css/")
	{
		$cssUrl = '<link href="'.$source.$css.'.css" rel="stylesheet" type="text/css" />';
		return $cssUrl;
	}
	public function getJs($url, $source = "js/")
	{
		$jsUrl = '<script type="text/javascript" src="'.$source.$url.'.js"></script>';
		return $jsUrl;
	}
	public function getNivoSlider($mostrar = FALSE)
	{
		// construir funcion con Base de datos y foreach
		if ($mostrar) {
			$nivoSlider = '
			<div id="wrapper">
		        <div class="slider-wrapper theme-default">
		            <!--<div class="ribbon"></div>-->
		            <div id="slider" class="nivoSlider">
		            	<img src="images/banner/4f4107e730634-660x305.jpg" />
		            	<img src="images/banner/4f4108af4f5c4-660x305.jpg" />
		            	<img src="images/banner/4f41081e99fae-660x305.jpg" />
		            	<img src="images/banner/4f41085b4b4e5-660x305.jpg" />
		            	<img src="images/banner/4f41088e686b9-660x305.jpg" />
		            	<img src="images/banner/4f410765da9bd-660x305.jpg" />
		            	<img src="images/banner/4f410800c334d-660x305.jpg" />
		            	<img src="images/banner/4f410847b96d3-660x305.jpg" />
		            	<img src="images/banner/4f4108774e87d-660x305.jpg" />
						<!--
		            	
						<img src="images/banner/toystory.jpg" alt="" />
						<a href=""><img src="images/banner/up.jpg" alt="" title="This is an example of a caption" /></a>
						<img src="images/banner/walle.jpg" alt="" data-transition="slideInLeft" />
						<img src="images/banner/nemo.jpg" alt="" title="#htmlcaption" />
		                
						-->
		            </div>
		            <!--
		            <div id="htmlcaption" class="nivo-html-caption">
		                <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>.
		            </div>
		            -->
		    	</div>
			</div>';
		} else {
			$nivoSlider = "";
		}
		return $nivoSlider;
	}
	function sendEmail($nombre, $email, $asunto, $contenido, $website = 'No website')
	{
		$contenido = nl2br($contenido);
		$para = 'kleith.vdp89@gmail.com';
		$titulo = $asunto;
		$mensaje = '
		<img src="http://www.kleith.com.ar/images/sergioMartinez.png" alt="Kleith" /><br>
		<b style="color: #204565">Fecha de envío: </b>'.date("d-m-Y || H:i").'<br>
		<b style="color: #204565">Nombre: </b>'.$nombre.'<br>
		<b style="color: #204565">Email: </b>'.$email.'<br>
		<b style="color: #204565">Website: </b><a href="'.$website.'" target="_blank">'.$website.'</a><br><br>
		<b style="color: #204565">Asunto: </b>'.$asunto.'<br>
		'.$contenido;
		$cabeceras = 'MIME-Version: 1.0'."\r\n";
		$cabeceras.= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
		$cabeceras.= 'From: Kleith | Contacto <administracion@kleith.com.ar>'."\r\n".
		    		 'Reply-To: administracion@kleith.com.ar'."\r\n";
		mail($para, $titulo, $mensaje, $cabeceras);
	}
	function get_last_ten_entries()
	{
		$query = $this->db->get('entries', 10);
		return $query->result();
	}
	
	function insert_entry()
	{
		$this->title   = $_POST['title']; // please read the below note
		$this->content = $_POST['content'];
		$this->date    = time();
	
		$this->db->insert('entries', $this);
	}
	
	function update_entry()
	{
		$this->title   = $_POST['title'];
		$this->content = $_POST['content'];
		$this->date    = time();
		
		$this->db->update('entries', $this, array('id' => $_POST['id']));
	}

}
?>